package com.heima.article.feign;

import com.heima.apis.article.IArticleClient;
import com.heima.article.service.ApArticleService;
import com.heima.model.article.dtos.ArticleDto;
import com.heima.model.comment.dtos.CommentArticleDto;
import com.heima.model.comment.dtos.CommentOperationDto;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.StatisticsPageDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * @author 陈辉
 * @data 2023 15:11
 */
@RestController
public class ArticleClient implements IArticleClient {

    @Autowired
    private ApArticleService apArticleService;

    @PostMapping("/api/v1/article/save")
    @Override
    public ResponseResult saveArticle(ArticleDto dto) {
//        try {
//            //模拟服务故障阻塞
//            Thread.sleep(10000);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
        return apArticleService.saveOrUpdateArticle(dto);
    }

    @PostMapping("/api/v1/article/quest")
    @Override
    public ResponseResult AllArticle(Integer id) {
        return apArticleService.getNameById(id);
    }

    @PostMapping("/api/v1/article/find_news_comments")
    @Override
    public ResponseResult findNewsComments(CommentArticleDto dto) {
        return apArticleService.findNewsComments(dto);
    }

    @Override
    @PostMapping("/api/v1/article/update_comment_status")
    public ResponseResult updateArticleStatus(CommentOperationDto dto) {
        return apArticleService.updateArticleStatus(dto);
    }

    /**
     * 图文统计
     * @param wmUserId
     * @param beginDate
     * @param endDate
     * @return
     */
    @Override
    @GetMapping("/api/v1/article/statisticsNum")
    public ResponseResult statisticsNum(@RequestParam("wmUserId") Integer wmUserId, @RequestParam("beginDate") Date beginDate, @RequestParam("endDate") Date endDate) {
        return apArticleService.statisticsNum(wmUserId,beginDate,endDate);
    }

    /**
     * 图文统计-分页统计
     * @param statisticsPageDto
     * @return
     */
    @Override
    @PostMapping("/api/v1/article/newPage")
    public ResponseResult newPage(@RequestBody StatisticsPageDto statisticsPageDto) {
        return apArticleService.newPage(statisticsPageDto);
    }
}
